package com.example.gzysmartcity.utils;

import android.content.Context;
import android.content.res.Resources;
import android.util.DisplayMetrics;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.PopupWindow;

public class PopupUntil {

    private PopupWindow p;

    public View getPopupDataByLayId(int layId, Context c) {
        Resources resources = c.getResources();
        DisplayMetrics metrics = resources.getDisplayMetrics();
        int wei = metrics.widthPixels;
        int hei = metrics.heightPixels;
        View v = LayoutInflater.from(c).inflate(layId, null);
        p = new PopupWindow(v);
        p.setWidth(wei);
        p.setHeight(hei);
        p.setFocusable(true);
        p.showAtLocation(v, Gravity.CENTER, 0, 0);
        return v;
    }


    public void getPopupDataByView(View v, Context c) {
        Resources resources = c.getResources();
        DisplayMetrics metrics = resources.getDisplayMetrics();
        int wei = metrics.widthPixels;
        int hei = metrics.heightPixels;
        p = new PopupWindow(v);
        p.setWidth(wei);
        p.setHeight(hei);
        p.setFocusable(true);
        p.showAtLocation(v, Gravity.CENTER, 0, 0);
    }

    public void closePopup() {
        p.dismiss();
    }
}
